package com.tender.common;

import lombok.Data;
import java.util.Optional;
import com.tender.constants.Constants;

import java.util.List;

@Data
public class PageInfo {
    private List<OrderInfo> orderInfos;
    private Long pageIndex = 1L;
    private Long pageSize = 10L;
    private Long total;
    /*** 总页数 ***/
    private long pages;

    public PageInfo() {
    }

    public PageInfo(Long pageIndex, Long pageSize) {
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
    }

    public Long getPageIndex() {
        return Optional.ofNullable(pageIndex).orElse(Constants.DEFAULT_PAGE_INDEX.longValue());
    }

    public void setPageIndex(Long pageIndex) {
        this.pageIndex = pageIndex;
    }

    public Long getPageSize() {
        return Optional.ofNullable(pageSize).orElse(Constants.DEFAULT_PAGE_SIZE.longValue());
    }

    public void setPageSize(Long pageSize) {
        this.pageSize = pageSize;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public long getPages() {
        return pages;
    }

    public void setPages(long pages) {
        this.pages = pages;
    }

    public Long getOffset() {
        return (this.getPageIndex() - Constants.ONE) * this.getPageSize();
    }

}
